<?php
function lilina_userapi_search($args) 
{
    if (empty($args) || count($args) < 1) {
        return;
    }
    $modid = '';
    extract($args);
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $stable = &$xartable['story'];
    $where = '';
    // initialize the commentlist array
    $commentlist = array();
    $q = xarVarPrepForDisplay($q);
    if (substr_count($q, ' ') > 1){
        $query = "SELECT xar_id,
                         xar_title,
                         xar_summary,
                         xar_link,
                         xar_timestamp,
                         xar_ctitle,
                         xar_curl,
                         xar_cfavicon,
                         xar_unique
                FROM $stable
                WHERE MATCH(xar_title, xar_summary) AGAINST ('$q')";
        $result =& $dbconn->SelectLimit($query, 5, 0);
    } else {
        $query = "SELECT xar_id,
                         xar_title,
                         xar_summary,
                         xar_link,
                         xar_timestamp,
                         xar_ctitle,
                         xar_curl,
                         xar_cfavicon,
                         xar_unique
                FROM $stable
                WHERE xar_title LIKE ? OR xar_summary LIKE ?
                ORDER BY xar_timestamp DESC";

        $bindvars = array($q, $q);
        $result =& $dbconn->SelectLimit($query, 40, 0, $bindvars);
    }

    if (!$result) return;
    if ($result->EOF) {
        return array();
    }
    for (; !$result->EOF; $result->MoveNext()) {
        list($id, $title, $summary, $link, $timestamp, $ctitle, $curl, $cfavicon, $unique) = $result->fields;
        if (xarSecurityCheck('OverviewLilina')) {
            $links[] = array('id'       => $id,
                             'title'    => $title,
                             'summary'  => $summary,
                             'link'     => $link,
                             'timestamp'=> $timestamp,
                             'ctitle'   => $ctitle,
                             'curl'     => $curl,
                             'cfavicon' => $cfavicon,
                             'unique'   => $unique);
        }
    }
    $result->Close();
    return $links;
}
?>